<template>
    <div class="vehicle-exhibition">
        <div class="item" :style="{ width: width }" v-for="item in props.data">
            <img src="@/assets/images/基础/icon_告警统计.png" alt="" />

            <div class="item-top">
                <div class="top">
                    <div class="count">{{ item.count }}</div>
                    <div class="unit">{{ item.unit }}</div>
                </div>
                <div class="name">{{ item.name }}</div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'

const props = defineProps({
    data: {
        type: Object,
        default: () => [
            {
                count: 2000,
                unit: '',
                name: '车位总数'
            },
            {
                count: 75,
                unit: '%',
                name: '空置率'
            },
            {
                count: 500,
                unit: '',
                name: '剩余车位'
            }
        ]
    }
})

const width = ref('45%')

watch(
    props.data,
    newVal => {
        if (newVal.length == 2) {
            width.value = '47%'
        } else if (newVal.length == 3) {
            width.value = '30%'
        } else if (newVal.length == 4) {
            width.value = '25%'
        }
    },
    {
        immediate: true
    }
)
</script>

<style scoped lang="scss">
.vehicle-exhibition {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    color: #fff;
    .item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-around;
        background: url('@/assets/images/基础/warnleft_bg.png') no-repeat;
        background-size: 100% 100%;
        height: 204px;
        font-family: OPPOSans;
        font-size: 14px;
        .item-top {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            .top {
                display: flex;
                align-items: flex-end;
                margin-bottom: 10px;
                .count {
                    font-family: SJyunhei;
                    font-size: 24px;
                    margin-right: 5px;
                    letter-spacing: 2px;
                }
                .unit {
                }
            }
            .name {
                color: #89cbff;
                text-align: center;
            }
        }

        img {
            width: 55px;
            height: 68px;
            margin-top: 20px;
        }
    }
}
</style>
